import 'package:flutter/material.dart';

import 'global_context.dart';

/// 封装通用的页面跳转方法，带右侧滑入动画效果
Future<T?> navigateTo<T>(Widget page, {
  Offset beginOffset = const Offset(1, 0),
  Curve curve = Curves.ease,
}) {
  return Navigator.of(globalContext!).push<T>(
    PageRouteBuilder(
      pageBuilder: (_, __, ___) => page,
      transitionsBuilder: (_, animation, __, child) {
        final tween = Tween<Offset>(begin: beginOffset, end: Offset.zero)
            .chain(CurveTween(curve: curve));
        return SlideTransition(
          position: animation.drive(tween),
          child: child,
        );
      },
    ),
  );
}
